<template>
  <div>
         <div>{{teacher.name}}</div>
    <div>{{teacher.age}}</div>
    <div>{{teacher.salary}}</div>
    <button @click="timeFly">过了一年</button>
   </div>
</template>
 
<script>
export default {

  data() {
    return {
            teacher:{
        name:"harry",
        age:28,
        salary:3000
      }
    };
  },
  watch: {
    "teacher.age"(newAge,oldAge){
      console.log(newAge,oldAge);
      if(newAge ===40){
        alert('您该退休了'+'您的年纪是'+ this.teacher.age+'您的工资是'+'this.teacher.salary')
      }
      else{
        return oldAge
      }
    },
  },
  methods: {
        timeFly() {
      this.teacher.age += 1
      this.teacher.salary += 500
    }
  }
};
</script>

<style scoped>
     
</style>